﻿Public Class SanPhamDAO
    Public Shared Function SelectAll() As DataTable
        Dim strSQL As String = "select IDMaSP,TenSp,DonViTinh,Gia,TenNhaCC as 'Ten Nha Cung Cap',SoLuong from SANPHAM sp, NHACUNGCAP ncc where sp.IDNhaCC=ncc.IDNhaCC"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Sub Insert(ByVal _sanpham As SanPhamDTO)
        Dim strSQL As String = "Insert into SANPHAM(TenSp,DonViTinh,Gia,IDNhaCC,SoLuong) Values ('" & _sanpham.TenSanPham & "','" & _sanpham.DonViTinh & "',' " & _sanpham.Gia & "'," & _sanpham.MaNhaCC & "," & _sanpham.SoLuong & ")"
        SQLProvider.ExecNoneQuery(strSQL)

    End Sub

    Public Shared Sub Delete(ByVal _sanpham As SanPhamDTO)
        Dim strSQL As String = "delete from SANPHAM where IDMaSP = " & _sanpham.MaSanPham
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Sub Update(ByVal _sanpham As SanPhamDTO)
        Dim strSQL As String = "Update SANPHAM set TenSp = '" & _sanpham.TenSanPham & "', DonViTinh = '" & _sanpham.DonViTinh & "', Gia = " & _sanpham.Gia & ",IDNhaCC = " & _sanpham.MaNhaCC & ", SoLuong=" & _sanpham.SoLuong & " where IDMaSP = " & _sanpham.MaSanPham
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

End Class
